CREATE TABLE TB_PRODUCT
(
	ID_PRODUCT      NUMBER(8) NOT NULL,
	NM_PRODUCT VARCHAR(75) NOT NULL,
	DS_PRODUCT VARCHAR(250) NULL,
	VL_TAX_AMOUNT NUMBER(8, 2) NOT NULL,
	ES_ACTIVE NUMBER(1) NOT NULL,
	ES_ALLOW_CUSTOM_AMMOUNT NUMBER(1) NOT NULL,
	VL_CALC_TYPE NUMBER(8) NOT NULL,
)
;

ALTER TABLE TB_PRODUCT ADD CONSTRAINT PK_TB_PRODUCT
	PRIMARY KEY (ID_PRODUCT)
;

CREATE SEQUENCE SEQ_TB_PRODUCT
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  START WITH 1
  INCREMENT BY 1
  CACHE 20;

CREATE OR REPLACE TRIGGER TI_TB_PRODUCT
BEFORE INSERT ON TB_PRODUCT
FOR EACH ROW
BEGIN
	IF :new.ID_PRODUCT IS NULL THEN
		SELECT SEQ_TB_PRODUCT.nextval INTO :new.ID_PRODUCT FROM DUAL;
	END IF;
END;

CREATE TABLE TB_TAX_INDEX
(
	NM_TAX_KEY VARCHAR(50) NOT NULL,
	NM_TAX VARCHAR(75) NOT NULL,
	DS_TAX VARCHAR(250) NULL,
	VL_TAX_AMOUNT NUMBER(8, 2) NOT NULL,
)
;

ALTER TABLE TB_TAX_INDEX ADD CONSTRAINT PK_TB_TAX_INDEX
	PRIMARY KEY (NM_TAX_KEY)
;

CREATE TABLE TB_RISK_PROFILE
(
	ID_RISK_PROFILE NUMBER(8) NOT NULL,
	NM_RISK_PROFILE VARCHAR(75) NOT NULL,
	DS_RISK_PROFILE VARCHAR(250) NULL,
	VL_INCOME_PERCENTUAL NUMBER(8, 2) NOT NULL,
)
;

ALTER TABLE TB_RISK_PROFILE ADD CONSTRAINT PK_TB_RISK_PROFILE
	PRIMARY KEY (ID_RISK_PROFILE)
;

CREATE SEQUENCE SEQ_TB_RISK_PROFILE
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  START WITH 1
  INCREMENT BY 1
  CACHE 20;

CREATE OR REPLACE TRIGGER TI_TB_RISK_PROFILE
BEFORE INSERT ON TB_RISK_PROFILE
FOR EACH ROW
BEGIN
	IF :new.ID_RISK_PROFILE IS NULL THEN
		SELECT SEQ_TB_RISK_PROFILE.nextval INTO :new.ID_RISK_PROFILE FROM DUAL;
	END IF;
END;

CREATE TABLE TB_SIMULATION
(
	ID_SIMULATION NUMBER(8) NOT NULL,
	NM_USER_NAME VARCHAR(100) NOT NULL,
	DS_USER_EMAIL VARCHAR(100) NOT NULL,
	DS_USER_DOCUMENT VARCHAR(20) NOT NULL,
	DS_USER_TELEPHONE VARCHAR(12) NOT NULL,
	DS_USER_TELEPHONE2 VARCHAR(12) NULL,
	VL_INITIAL_AMOUNT NUMBER(8, 2) NOT NULL,
	ES_RETIREMENT NUMBER(1) NULL,
	DS_OBJECTIVE VARCHAR(100) NULL,
	VL_REQUIRED_AMOUNT NUMBER(8,2) NULL,
	VL_MONTHLY_APPLICATION NUMBER(8,2) NULL,
	VL_INVESTMENT_TIME NUMBER(8) NULL,
	VL_INVESTMENT_TIME_TYPE NUMBER(8) NULL,
	VL_SUITABILITY_TAX NUMBER(8,2) NULL,
	VL_CURRENT_AGE NUMBER(8) NULL,
	VL_RETIREMENT_START_AGE NUMBER(8) NULL,
	VL_RETIREMENT_FINISH_AGE NUMBER(8) NULL,
)
;


ALTER TABLE TB_SIMULATION ADD CONSTRAINT PK_TB_SIMULATION
	PRIMARY KEY (ID_SIMULATION)
;

CREATE SEQUENCE SEQ_TB_SIMULATION
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  START WITH 1
  INCREMENT BY 1
  CACHE 20;

CREATE OR REPLACE TRIGGER TI_TB_SIMULATION
BEFORE INSERT ON TB_SIMULATION
FOR EACH ROW
BEGIN
	IF :new.ID_SIMULATION IS NULL THEN
		SELECT SEQ_TB_SIMULATION.nextval INTO :new.ID_SIMULATION FROM DUAL;
	END IF;
END;





CREATE TABLE TB_COMPARSION
(
	ID_COMPARSION NUMBER(8) NOT NULL,
	NM_USER_NAME VARCHAR(100) NOT NULL,
	DS_USER_EMAIL VARCHAR(100) NOT NULL,
	DS_USER_DOCUMENT VARCHAR(20) NOT NULL,
	DS_USER_TELEPHONE VARCHAR(12) NOT NULL,
	DS_USER_TELEPHONE2 VARCHAR(12) NULL,
	VL_INITIAL_AMOUNT NUMBER(8, 2) NOT NULL,
	ES_RETIREMENT NUMBER(1) NULL,
	DS_OBJECTIVE VARCHAR(100) NULL,
	VL_REQUIRED_AMOUNT NUMBER(8,2) NULL,
	VL_MONTHLY_APPLICATION NUMBER(8,2) NULL,
	VL_INVESTMENT_TIME NUMBER(8) NULL,
	VL_INVESTMENT_TIME_TYPE NUMBER(8) NULL,
	VL_SUITABILITY_TAX NUMBER(8,2) NULL,
	VL_CURRENT_AGE NUMBER(8) NULL,
	VL_RETIREMENT_START_AGE NUMBER(8) NULL,
	VL_RETIREMENT_FINISH_AGE NUMBER(8) NULL,
)
;


ALTER TABLE TB_COMPARSION ADD CONSTRAINT PK_TB_COMPARSION
	PRIMARY KEY (ID_COMPARSION)
;

CREATE SEQUENCE SEQ_TB_COMPARSION
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  START WITH 1
  INCREMENT BY 1
  CACHE 20;

CREATE OR REPLACE TRIGGER TI_TB_COMPARSION
BEFORE INSERT ON TB_COMPARSION
FOR EACH ROW
BEGIN
	IF :new.ID_COMPARSION IS NULL THEN
		SELECT SEQ_TB_COMPARSION.nextval INTO :new.ID_COMPARSION FROM DUAL;
	END IF;
END;

CREATE TABLE TB_COMPARSION_PRODUCT
(
	ID_COMPARSION NUMBER(8) NOT NULL,
	ID_PRODUCT NUMBER(8) NOT NULL,
)
;

ALTER TABLE TB_COMPARSION_PRODUCT ADD CONSTRAINT PK_TB_COMPARSION_PRODUCT
	PRIMARY KEY (ID_COMPARSION, ID_PRODUCT)
;



